home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #49 (Oct 89) / Driver Code / DRVRStruct.a next >
Text File  |  1988-01-06  |  9KB  |  323 lines

  1.         TITLE    'DRVRStart - Parse a driver declaration'
  2.         
  3.         MACRO
  4. &Scope    DRVRStart &ArgList,&Link
  5.         PRINT    Push,NoMDir,NoMCall
  6. .*
  7.         GBLC        &ModName#            ; <modname>
  8.         GBLC        &FInfo#            ; function <result>
  9.         GBLC        &Args#[50]        ; argument list
  10.         GBLA        &NbrOfArgs#        ; number of args in argument list
  11.         GBLC        &StFrame#            ; name of current stack frame
  12.         GBLC        &DbgName#            ; name to generate for MacsBug
  13.         GBLC        &FSz#            ; function result size
  14.         GBLA        &Link#            ; 1 ==> generate LINK
  15.         GBLA        &HaveDcls#        ; 1 ==> have local variables
  16.         GBLA        &C#                ; 1 ==> C function
  17. .*
  18.         LCLA        &Func,&Arg
  19.         LCLC        &LinkOpt
  20. .*
  21. .* LinkAll is a user setable global controlling LINK generation
  22. .*
  23.     IF &Type('LinkAll') = 'UNDEFINED' THEN ; Initialize LinkAll if required
  24.       PRINT Push,Off
  25.       LinkAll: SET 0
  26.       PRINT Pop
  27.     ENDIF
  28. .*
  29. .* Debug is a user setable global controlling MacsBug symbol generation
  30. .*
  31.     IF &Type('Debug') = 'UNDEFINED' THEN ; Initialize Debug if required
  32.       PRINT Push,Off
  33.       Debug: SET 0
  34.       PRINT Pop
  35.     ENDIF
  36. .*
  37. .* Break up &ArgList into its components
  38. .*
  39.     ScanArgs#    &ArgList                ; Set &ModName#, &Args#, &FInfo#
  40.     &Func: SETA 0                        ;&Len(&FInfo#)        ; &Func ≠ 0 if function
  41.     &C#:   SETA 0                        ;&UC(&C)='C'            ; Remember if we have a C function
  42. .*
  43. .*
  44. .* Generate module header and its corresponding scope
  45. .*
  46. &ModName# MAIN      &Scope
  47. .*
  48. .* Start the proc's local stack frame
  49. .*
  50.     &StFrame#: SETC &Concat('SF#', &SysNdx)
  51. .*
  52. &StFrame# RECORD    {FramePtr},Decr
  53. .*
  54.       &FSz#: SETC ''
  55. .*
  56. .* The return address always follows the formal list
  57. .*
  58. RetAddr   DS.L      1
  59. .*
  60. .* Process the &Link parameter: indicates if LINK must be generated and whether
  61. .* MacsBug symbol will be generated.
  62. .*
  63.     &Link#:   SETA 0                ; Assume LINK will not be needed
  64.     &LinkOpt: SETC &UC(&Link)
  65.     IF Debug THEN                    ; If Debug ≠ 0 then...
  66.       &LinkOpt: SETC 'DEBUG'            ; ...we will gen LINK and MacsBug symbol
  67.     ELSEIF LinkAll THEN                ; If LinkAll ≠ 0 then...
  68.       IF &LinkOpt ≠ 'DEBUG' THEN        ; ...if user didn't specify DEBUG for &Link
  69.         &LinkOpt: SETC 'Y'            ; indicate we need the LINK
  70.       ENDIF
  71.     ENDIF
  72.     IF &LinkOpt ≠ '' THEN            ; Any &Link or global control setting ?
  73.       &Link#: SETA 1                ; Yes, set switch to gen LINK later
  74.       IF (&LinkOpt ≠ 'DEBUG') OR (&ModName# = '') THEN
  75.         &DbgName#: SETC ''            ; If no MacsBug symbol, set global <null>
  76.       ELSE                        ; If MacsBug symbol, set it to gen later
  77.         &DbgName#: SETC &Concat(&UC(&ModName#), '        ')
  78.       ENDIF
  79.     ENDIF
  80. .*
  81. .* That's all for now -- we have no local declarations at this point...yet!
  82. .*
  83.     &HaveDcls#: SETA 0
  84. .*
  85.         ENDM
  86.  
  87.         TITLE    'DRVRBegin - Driver primary entry point'
  88.         
  89.         MACRO
  90.         DRVRBegin    &Prelude,&Save==,&With==
  91.         PRINT    Push,NoMDir,NoMCall
  92.         
  93.         GBLC        &FInfo#            ; function <result>
  94.         GBLC        &StFrame#            ; name of current stack frame
  95.         GBLC        &SaveRegs#        ; Regs saved and to be restored
  96.         GBLA        &NbrOfArgs#        ; number of args in argument list
  97.         GBLA        &Link#            ; 1 ==> generate LINK
  98.         GBLA        &HaveDcls#        ; 1 ==> have local variables
  99.         GBLA        &ArgSize#            ; nbr of bytes of stack space for formals
  100. .*
  101. .* If we don't already think we need a LINK, we still may need it if, at this
  102. .* point, we have to save registers and we are in a function or there are formal
  103. .* parameters.
  104. .*
  105.     IF &Link# OR (((&FInfo#≠'') OR (&NbrOfArgs# ≠ 0)) AND (&Save≠'')) THEN
  106.       &Link#: SETA 1                ; Link is required
  107.       IF NOT &HaveDcls# THEN            ; Gen field for LINK address if no locals
  108. LinkA6    DS.L      1
  109.       ENDIF
  110.     ENDIF
  111. .*
  112. .* If there we no locals, we haven't generated the FramePtr yet.  So we do it now.
  113. .*
  114.     IF NOT &HaveDcls# THEN
  115. FramePtr  EQU       *
  116.     ENDIF
  117. .*
  118. .* That's all for the stack frame. We generate LocalSize to be used in potential
  119. .* LINK instruction.
  120. .*
  121. LocalSize DS.W      0
  122.           ENDR
  123. .*
  124. .* Generate a WITH to cover the local stack frame and any additional templates
  125. .* the user specified in the &With parameter.  This may be a sublist or a single
  126. .* name.
  127. .*
  128.     IF &With ≠ '' THEN
  129.       IF &With[1:1] = '(' THEN
  130.           WITH      &With[2:&Len(&With)-2],&StFrame#
  131.       ELSE
  132.           WITH      &With,&StFrame#
  133.       ENDIF
  134.     ELSE
  135.           WITH      &StFrame#
  136.     ENDIF
  137. .*
  138. .* It's time for the LINK.  It is generated if &Link is 1.  &Link became 1 under
  139. .* the following conditions:
  140. .*   1. Either the globals LinkAll or Debug are set non-zero.
  141. .*   2. The &Link Procedure parameter is set to DEBUG or non-null
  142. .*   3. There are local variables (Var's)
  143. .*   4. There are registers to save (&Save), and
  144. .*      • we are processing a function, or
  145. .*      • there are formal (and, of course, actual) parameters
  146. .* Given all this, the user can still suppress the LINK by setting &Prelude to
  147. .* non-null.
  148. .*
  149.     IF &Link# THEN
  150.       IF &Prelude = '' THEN
  151.           LINK      A6,#LocalSize
  152.       ENDIF
  153. FP        SET       A6
  154.     ELSE
  155. FP        SET       A7
  156.     ENDIF
  157. .*
  158. .* Compute the size of the argument list to be able to pop the stack with Return.
  159. .* Also, save registers if required.
  160. .*
  161.     &ArgSize#:  SETA &Eval(&StFrame#)-RetAddr-4
  162.     &SaveRegs#: SETC &Save
  163. .*
  164.         PRINT    Pop
  165.         ENDM
  166.  
  167.         
  168.         TITLE    'DRVREnter - Driver routine entry point'
  169.         
  170.         MACRO
  171. &Lbl        DRVREnter    &Prelude,&With==
  172.         
  173.         GBLC        &SaveRegs#        ; Regs saved and to be restored
  174.         GBLA        &Link#            ; 1 ==> generate LINK
  175. &Lbl ;
  176. .*
  177. .* Generate a WITH to cover any additional templates  the user specified in the
  178. .* &With parameter.  This may be a sublist or a single name.
  179. .*
  180.     IF &With ≠ '' THEN
  181.       IF &With[1:1] = '(' THEN
  182.           WITH      &With[2:&Len(&With)-2]
  183.       ELSE
  184.           WITH      &With
  185.       ENDIF
  186.     ENDIF
  187. .*
  188. .* It's time for another LINK.  It is generated if &Link is 1.  &Link became 1
  189. .* under the following conditions:
  190. .*   1. Either the globals LinkAll or Debug are set non-zero.
  191. .*   2. The &Link Procedure parameter is set to DEBUG or non-null
  192. .*   3. There are local variables (Var's)
  193. .*   4. There are registers to save (&Save), and
  194. .*      • we are processing a function, or
  195. .*      • there are formal (and, of course, actual) parameters
  196. .* Given all this, the user can still suppress the LINK by setting &Prelude to
  197. .* non-null.
  198. .*
  199.     IF &Link# THEN
  200.       IF &Prelude = '' THEN
  201.           LINK      A6,#LocalSize
  202.       ENDIF
  203.     ENDIF
  204. .*
  205. .* Save registers if required.
  206. .*
  207.     IF &SaveRegs# ≠ '' THEN
  208.       IF &Substr(&Type(&SaveRegs#), 1, 3) = 'REG' THEN
  209.           MOVE.L    &SaveRegs#,-(A7)
  210.       ELSE
  211.           MOVEM.L   &SaveRegs#,-(A7)
  212.       ENDIF
  213.     ENDIF
  214.  
  215.         ENDM
  216.  
  217.  
  218.         TITLE    'DRVRExit - Driver exit'
  219.         
  220.         MACRO
  221.         DRVRExit    &Trap,&Force==N
  222. .*
  223.         GBLC        &SaveRegs#        ; Regs saved and to be restored
  224.         GBLC        &DbgName#            ; name to generate for MacsBug
  225.         GBLA        &Link#            ; 1 ==> generate LINK
  226.         
  227.         LCLC        &S
  228. .*
  229. .* Gen code to restore any save registers
  230. .*
  231.     IF &SaveRegs# ≠ '' THEN
  232.       IF &Substr(&Type(&SaveRegs#), 1, 3) = 'REG' THEN
  233.           MOVE.L    (A7)+,&SaveRegs#
  234.       ELSE
  235.           MOVEM.L   (A7)+,&SaveRegs#
  236.       ENDIF
  237.     ENDIF
  238. .*
  239. .* If we generated the LINK, it's time for the UNLK
  240. .*
  241.     IF &Link# THEN
  242.           UNLK      A6
  243.     ENDIF
  244.  
  245.       MOVE.W        &Trap,D1
  246.       BTST            #noQueueBit,D1
  247.       BNE.S            %L%&SysNdx
  248.       MOVE.L    JIODone,-(SP)
  249. %L%&SysNdx:
  250.       RTS
  251. .*
  252. .* If we need to generate the MacsBug symbol, now is the time!  Be careful to
  253. .* make sure of the Assembler's STRING setting, since the MacsBug symbol must
  254. .* be an ASIS string.
  255. .*
  256.     IF &DbgName# ≠ '' THEN            ; &DbgName# indicates we have a symbol
  257.       &S: SETC &Setting('STRING')        ; Preserve STRING status
  258.       IF &S ≠ 'ASIS' THEN            ; Only change it if not already ASIS
  259.           STRING    ASIS
  260.           DC.B      '&DbgName#[1:8]'
  261.           STRING    &S
  262.       ELSE
  263.           DC.B      '&DbgName#[1:8]'
  264.       ENDIF
  265.     ENDIF
  266. .*
  267.         ENDM
  268.  
  269.         TITLE    'GNEExit - GNE filter exit'
  270.         
  271.         MACRO
  272.         GNEExit    &GNENext
  273. .*
  274.         GBLC        &SaveRegs#        ; Regs saved and to be restored
  275.         GBLC        &DbgName#            ; name to generate for MacsBug
  276.         GBLA        &Link#            ; 1 ==> generate LINK
  277.         
  278.         LCLC        &S
  279. .*
  280. .* Gen code to restore any save registers
  281. .*
  282.     IF &SaveRegs# ≠ '' THEN
  283.       IF &Substr(&Type(&SaveRegs#), 1, 3) = 'REG' THEN
  284.           MOVE.L    (A7)+,&SaveRegs#
  285.       ELSE
  286.           MOVEM.L   (A7)+,&SaveRegs#
  287.       ENDIF
  288.     ENDIF
  289. .*
  290. .* If we generated the LINK, it's time for the UNLK
  291. .*
  292.     IF &Link# THEN
  293.           UNLK      A6
  294.     ENDIF
  295.  
  296.       MOVE.L        &GNENext,-(SP)
  297.       RTS
  298. .*
  299. .* If we need to generate the MacsBug symbol, now is the time!  Be careful to
  300. .* make sure of the Assembler's STRING setting, since the MacsBug symbol must
  301. .* be an ASIS string.
  302. .*
  303.     IF &DbgName# ≠ '' THEN            ; &DbgName# indicates we have a symbol
  304.       &S: SETC &Setting('STRING')        ; Preserve STRING status
  305.       IF &S ≠ 'ASIS' THEN            ; Only change it if not already ASIS
  306.           STRING    ASIS
  307.           DC.B      '&DbgName#[1:8]'
  308.           STRING    &S
  309.       ELSE
  310.           DC.B      '&DbgName#[1:8]'
  311.       ENDIF
  312.     ENDIF
  313. .*
  314.         ENDM
  315.  
  316.         TITLE    'Dump file "DRVRStruct.d"'
  317.         
  318. ********************************************************************************
  319.         DUMP        'HD 40:MPW:AIncludes:DRVRStruct.d'
  320. ********************************************************************************
  321.         END        
  322.  
  323.